package com.xcesys.extras.dataobject.lookup;

import java.io.Serializable;
import java.util.Set;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;

/**
 * A class represents a code-label pair data.
 * 
 * @author Danne Leung
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ValueLabelItem")
public class ValueLabelItem implements Serializable {

	private static final long serialVersionUID = -3197115964364195815L;

	private Set<ValueLabelItem> children;

	private String value;

	private String desc;

	private Long id;

	private String label;

	private ValueLabelItem parent;

	private Long seq;

	public ValueLabelItem() {
	}

	public ValueLabelItem(Long id, String code, String name, String description) {
		super();
		this.id = id;
		this.value = code;
		this.label = name;
		this.desc = description;
	}

	public int compare(ValueLabelItem item) {
		return (this.getValue() + this.getLabel()).compareToIgnoreCase(item
				.getValue() + item.getLabel());
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (getClass() != obj.getClass())
			return false;
		final ValueLabelItem other = (ValueLabelItem) obj;
		if (value == null) {
			if (other.value != null)
				return false;
		} else if (!value.equals(other.value))
			return false;
		if (label == null) {
			if (other.label != null)
				return false;
		} else if (!label.equals(other.label))
			return false;
		return true;
	}

	public Set<ValueLabelItem> getChildren() {
		return children;
	}

	public String getDesc() {
		return desc;
	}

	public Long getId() {
		return id;
	}

	public String getLabel() {
		return label;
	}

	public ValueLabelItem getParent() {
		return parent;
	}

	public Long getSeq() {
		return seq;
	}

	public String getValue() {
		return value;
	}

	@Override
	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result + ((value == null) ? 0 : value.hashCode());
		result = PRIME * result + ((label == null) ? 0 : label.hashCode());
		return result;
	}

	public void setChildren(Set<ValueLabelItem> children) {
		Object oldValue = this.children;
		this.children = children;
		// firePropertyChange("childNodes", oldValue, childNodes);
	}

	public void setDesc(String description) {
		Object oldValue = this.desc;
		this.desc = description;
		// firePropertyChange("description", oldValue, description);
	}

	public void setId(Long id) {
		Object oldValue = this.id;
		this.id = id;
		// firePropertyChange("id", oldValue, id);
	}

	public void setLabel(String label) {
		Object oldValue = this.label;
		this.label = label;
		// firePropertyChange("label", oldValue, label);
	}

	public void setParent(ValueLabelItem parent) {
		Object oldValue = this.parent;
		this.parent = parent;
		// firePropertyChange("parentNode", oldValue, parentNode);
	}

	public void setSeq(Long seq) {
		Object oldValue = this.seq;
		this.seq = seq;
		// firePropertyChange("seq", oldValue, seq);
	}

	public void setValue(String code) {
		Object oldValue = this.value;
		this.value = code;
		// firePropertyChange("code", oldValue, code);
	}

	/**
	 * Constructs a <code>String</code> with all attributes in name = value
	 * format.
	 * 
	 * @return a <code>String</code> representation of this object.
	 */
	@Override
	public String toString() {
		final String TAB = "    ";

		String retValue = "";

		retValue = "CodeNameItem ( " + super.toString() + TAB + "id = "
				+ this.id + TAB + "code = " + this.value + TAB + "name = "
				+ this.label + TAB + "description = " + this.desc + TAB
				+ "seqNum = " + this.seq + TAB + " )";

		return retValue;
	}

}
